function cp_man() {
    let manTabPanel;
    let diyTabAry = [];
    let TblMfgCatIdInvAry = [], JarmodelAry = [], BoxAry = [], ResourceAry = [], InvAry = [], WorkShopLineList = [];
    function yPaiAddTab(title, storeId, cols, data) {
        let fields = [], columns = [
            { header: '', xtype: 'rownumberer', width: 45, align: 'center', sortable: false, menuDisabled: true },
        ]
        cols.forEach(function (item) {
            fields.push(item.dataIndex)
            item['menuDisabled'] = true;
            columns.push(item)
        })
        let tabID = 'diyTab' + storeId + 'Id'
        if (!manTabPanel.getComponent(tabID)) {
            Ext.create('Ext.data.Store', {
                storeId: storeId,
                fields: fields,
                data: data
            });
            let c = Ext.create('Ext.grid.Panel', {
                title: title,
                id: tabID,
                store: Ext.data.StoreManager.lookup(storeId),
                columns: columns
            });
            manTabPanel.add(c);
            diyTabAry.push(c)
        }
    }
    function wnd(list) {
        var columns = getPropertyList('V_0_sa_ordersdetail_NotFinsh', "1") || [];
        let startDate = Ext.create('Ext.form.DateField', {
            fieldLabel: '开始日期',
            labelWidth: 65,
            width: 175,
            format: 'Y/m/d',
            value: AddDate(new Date(),-60),
            listeners: {
                change: function (opt, newValue, oldValue, eOpts) {

                }
            }
        })
        let endDate = Ext.create('Ext.form.DateField', {
            fieldLabel: '截止日期',
            labelWidth: 65,
            width: 175,
            format: 'Y/m/d',
            value: AddDate(new Date(),30),
            listeners: {
                change: function (opt, newValue, oldValue, eOpts) {

                }
            }
        })
        var __searTbar = new Ext.Toolbar({
            dock: 'top',
            items: [
                startDate, endDate, {
                    text: '查询',
                    glyph: 0xf002,
                    handler: function () {
                        Wait.Start(null, "正在执行分析，请稍候.....");
                        var cond = {
                            t: "and", child: []
                        }
                        if (startDate.getValue()) {
                            cond.child.push({ c: "OrderDate", cp: '>=', v: startDate.getValue() })
                        }
                        if (endDate.getValue()) {
                            cond.child.push({ c: "OrderDate", cp: '<=', v: endDate.getValue() })
                        }
                        getListWithMultParams("V_0_sa_ordersdetail_NotFinsh", { _cdt: jsonEncode(cond), __all: true }, null, {
                            callback: function (vitems) {
                                Wait.hide();
                                console.log(vitems)
                                let tmp_ary = []
                                vitems.forEach(element => {
                                    if(!InvAry.find(x => x.InventoryID == element.Inventory_ID)){
                                        InvAry.push({
                                            InventoryID: element.Inventory_ID,
                                            Description: element.Description,
                                        })
                                    }
                                    tmp_ary.push({
                                        SaDate: element.OrderDate,
                                        InventoryID: element.Inventory_ID,
                                        Description: element.Description,
                                        Unit_Weight: element.Unit_Weight,
                                        JarmodelID: element.JARMODELID,
                                        BoxCode: element.BoxCode,
                                        ShipDate: element.ShipDate,
                                        Nbox: element.NBox,
                                        Resource_ID: '',
                                        NOID: element.NO,
                                        StkQty: 0,
                                        ScheduleStartDate: "",
                                        ScheduleEndDate: "",
                                        DeskQty: 0,
                                        ReqQty: element.Qty,
                                        ReqProcessed: 0,
                                        DailyEnergy: 0,
                                        ProcessingTime: 0,
                                        SaOrder: element.OrderID,
                                        MfgCatID: element.MfgCatID
                                    })
                                });
                                NotSaOrderGrid.getStore().removeAll();
                                NotSaOrderGrid.getStore().add(tmp_ary)
                            }, async: function () { }
                        });
                    }
                }
            ]

        });
        let __fields = [], cols = [{ header: '', xtype: 'rownumberer', width: 45, align: 'center', sortable: false, menuDisabled: true }]
        for (let col in columns) {
            const element = columns[col];
            if (element.dataIndex) {
                __fields.push(element.dataIndex)
                cols.push({
                    text: element.displayName, dataIndex: element.dataIndex, sortable: false, menuDisabled: true
                })
            }
            console.log(columns[col])
        }
        var NotSaOrderGrid = getTop().Ext.create('Ext.grid.Panel', {
            store: Ext.create('Ext.data.Store', {
                fields: __fields,
                sortable: true,
                //sorters: [{ property: "ReqDate", direction: "ASC" }], //给定一个默认的排序方式      
                data: list
            }),
            region: 'south',
            frame: false,
            width: 900,
            height: '100%',
            viewConfig: {
                columnLines: true,
                stripeRows: true,
                enableTextSelection: true,
                animateShadow: true,
                forceFit: true,
                getRowClass: function (record) {
                    if (record.get('ProjectIssueType') == -1 || record.get('IsIssue') == 1) {
                        return 'bglightred'
                    }
                }
            },
            selModel: {
                mode: 'MULTI',
                checkboxSelect: true,
                injectCheckbox: 1,
                type: 'checkboxmodel',
                listeners: {
                    beforeselect: function (that, record, index, eOpts) {
                        console.log(that)
                        that.disable(true)
                        if (record.get('ProjectIssueType') == -1 || record.get('IsIssue') == 1) {
                            return false
                        }
                    }
                }
            },
            columns: cols,
            dockedItems: [__searTbar]
        });
        var init_wind = getTop().Ext.create('Ext.window.Window', {
            title: '未清销售订单',
            width: 830,
            height: 480,
            modal: true,
            maximizable: true,
            items: [NotSaOrderGrid],
            listeners: {
                resize: function (wn, width, height, eOpts) {
                    let NotSaOrderGrid = wn.items.items[0];
                    NotSaOrderGrid.setHeight(height - 80);
                    NotSaOrderGrid.setWidth(width - 15);
                }
            },
            fbar: [
                {
                    type: 'button',
                    text: '选择',
                    handler: function () {
                        let selectrows = NotSaOrderGrid.getSelectionModel().getSelection();
                        if (selectrows.length > 0) {
                            let tmp_ary = []
                            for (var i = 0; i < selectrows.length; i++) {
                                const element = selectrows[i].getData();
                                InvAry.push({
                                    InventoryID: element.Inventory_ID,
                                    Description: element.Description,
                                })
                                tmp_ary.push({
                                    SaDate: element.OrderDate,
                                    InventoryID: element.Inventory_ID,
                                    Description: element.Description,
                                    Unit_Weight: element.Unit_Weight,
                                    JarmodelID: element.JARMODELID,
                                    BoxCode: element.BoxCode,
                                    ShipDate: element.ShipDate,
                                    Nbox: element.NBox,
                                    Resource_ID: '',
                                    NOID: element.NO,
                                    StkQty: 0,
                                    ScheduleStartDate: "",
                                    ScheduleEndDate: "",
                                    DeskQty: 0,
                                    ReqQty: element.Qty,
                                    ReqProcessed: 0,
                                    DailyEnergy: 0,
                                    ProcessingTime: 0,
                                    SaOrder: element.OrderID,
                                    MfgCatID: element.MfgCatID
                                })
                            }
                            grid.getStore().add(tmp_ary)
                            init_wind.close();
                            return true;
                        } else {
                            Alert('提示：', '请选择数据！');
                            return false;
                        }
                    }
                }, {
                    type: 'button',
                    text: '取消',
                    handler: function () {
                        init_wind.close();
                    }
                }
            ]
        });
        init_wind.show();
    }
    /**
    * 数组去重
    **/
    Array.prototype.distinct = function () {
        var arr = this, result = [], i, j, len = arr.length;
        for (i = 0; i < len; i++) {
            for (j = i + 1; j < len; j++) {
                if (arr[i] === arr[j]) {
                    j = ++i;
                }
            }
            result.push(arr[i]);
        }
        return result;
    }
    function AddDate(date, days) {
        if (days == undefined) {
            days = 1;
        }
        var date = new Date(date);
        date.setDate(date.getDate() + days);
        return date;
    }
    //自动排序
    function autoSort() {
        let obj = new Object();
        store.suspendEvents();
        store.each(function (record) {
            let resourceId = record.get('Resource_ID').replace(".", "");
            if (resourceId && resourceId != "未配置") {
                let ReqProcessed = parseFloat(record.get('ReqProcessed'));
                let InvID = record.get('InventoryID').replace(".", "");
                resourceId = resourceId + InvID;
                var hours = parseFloat(record.get('ProcessingTime'))

                if (obj[resourceId]) {
                    if (Object.keys(obj).find(x => x == resourceId)) {

                        if (ReqProcessed > 0) {
                            record.set('ScheduleStartDate', AddDate(obj[resourceId], 1).format('yyyy-MM-dd'))
                            obj[resourceId] = new Date(AddDate(obj[resourceId], hours))
                            record.set('ScheduleEndDate', JSON.stringify(AddDate(obj[resourceId], 0).format('yyyy-MM-dd')).replace(/\"/g, ""))
                        } else {
                            record.set('ScheduleStartDate', obj[resourceId].format('yyyy-MM-dd'))
                            obj[resourceId] = new Date(obj[resourceId])
                            record.set('ScheduleEndDate', JSON.stringify(new Date(obj[resourceId]).format('yyyy-MM-dd')).replace(/\"/g, ""))
                        }

                    }
                } else {
                    record.set('ScheduleStartDate', AddDate(record.get("SaDate"), 1).format('yyyy-MM-dd'))
                    obj[resourceId] = new Date(AddDate(record.get("ScheduleStartDate"), hours - 1))
                    record.set('ScheduleEndDate', JSON.stringify(AddDate(obj[resourceId], 0).format('yyyy-MM-dd')).replace(/\"/g, ""))

                }
            }
        })
        store.resumeEvents();
        grid.getView().refresh();
        Alert('提示：', '预排完成！')
    }
    var store = Ext.create('Ext.data.Store', {
        fields: ['SaDate', 'InventoryID', 'Description', 'Resource_ID', 'StkQty', 'ScheduleStartDate', 'ScheduleEndDate','QtyNotOrder',
            'DeskQty', 'ReqQty', 'ReqProcessed', 'DailyEnergy', 'ProcessingTime', 'SaOrder', 'NOID', 'Shortage_Qty', 'MfgCatID', 'ShipDate',
        'QtyNotFinish'],
        data: [],
        sorters: [{ property: "InventoryID", direction: "ASC" }], //给定一个默认的排序方式      
        //groupField: 'SaOrder',
    });

    var toolTbar = new Ext.Toolbar({
        dock: 'top',
        items: [
            {
                text: '读销售订单',
                glyph: 0xf058,
                handler: function () {

                    Wait.Start(null, "正在执行分析，请稍候.....");
                    var cond = {
                        t: "and", child: [
                            { c: "OrderDate", cp: '>=', v: '2021-08-30' },
                            { c: "OrderDate", cp: '<=', v: '2021-09-01' }
                        ]
                    }
                    getListWithMultParams("V_0_sa_ordersdetail_NotFinsh", { _cdt: jsonEncode(cond), __all: true }, null, {
                        callback: function (vitems) {
                            Wait.hide();
                            wnd(vitems);
                            console.log(vitems)
                            let tmp_ary = []
                            vitems.forEach(element => {
                                InvAry.push({
                                    InventoryID: element.Inventory_ID,
                                    Description: element.Description,
                                })
                                tmp_ary.push({
                                    SaDate: element.OrderDate,
                                    InventoryID: element.Inventory_ID,
                                    Description: element.Description,
                                    Unit_Weight: element.Unit_Weight,
                                    JarmodelID: element.JARMODELID,
                                    BoxCode: element.BoxCode,
                                    ShipDate: element.ShipDate,
                                    Nbox: element.NBox,
                                    Resource_ID: '',
                                    NOID: element.NO,
                                    StkQty: 0,
                                    ScheduleStartDate: "",
                                    ScheduleEndDate: "",
                                    DeskQty: 0,
                                    ReqQty: element.Qty,
                                    ReqProcessed: 0,
                                    DailyEnergy: 0,
                                    ProcessingTime: 0,
                                    SaOrder: element.OrderID,
                                    MfgCatID: element.MfgCatID
                                })
                            });
                            //grid.getStore().add(tmp_ary)
                        }, async: function () {

                        }
                    });

                }
            },
            {
                text: '分单',
                glyph: 0xf4ce,
                handler: function () {
                    store.suspendEvents();
                    store.each(function (record) {
                        let tmp = TblMfgCatIdInvAry.filter(function (item) {
                            if (item.MfgCatId == record.get('MfgCatID')) {
                                return item;
                            }
                        })
                        if (tmp.length > 0) {
                            record.set('Resource_ID', tmp[0].Resource_ID)
                            record.set('DailyEnergy', tmp[0].DayCapacity)
                        } else {
                            record.set('Resource_ID', '未配置')
                            record.set('DailyEnergy', 0)
                        }
                    });
                    store.resumeEvents();
                    grid.getView().refresh();
                    Alert('提示：', '分单完成')
                }
            },
            {
                text: '计算短缺',
                glyph: 0xf689,
                handler: function () {
                    Wait.Start(null, "正在执行查询，请稍候.....");
                    setTimeout(() => {
                        var ret = callProcedure({
                            name: 'ProProductMrpFG',
                            args: [{
                                name: 'WStkID', value: '*'
                            },
                            {
                                name: 'WProID', value: '*'
                            }]
                        });
                        var cond = {
                            t: "and", child: [
                                { c: "Evidence_Number", cp: '==', v: 'V0000001' }
                            ]
                        }
                        getListWithMultParams("TblSaProductStkMrp_Detail", { _cdt: jsonEncode(cond), __all: true }, null, {
                            callback: function (vitems) {
                                Wait.hide();
                                console.log(vitems)
                                store.suspendEvents();
                                let obj = new Object();
                                store.each(function (record) {
                                    let resourceId = record.get('Resource_ID').replace(".", "");
                                    if (resourceId && resourceId != "未配置") {
                                        let DailyEnergy = parseFloat(record.get('DailyEnergy'))
                                        let InvID = record.get('InventoryID').replace(".", "");
                                        resourceId = resourceId + InvID;
                                        let ProcessingTime = 0, ReqProcessed = 0;
                                        let mrp_obj = vitems.find(x => x.OrderID == record.get('SaOrder') && x.OrdNoid == record.get('NOID'))
                                        if (mrp_obj) {
                                            record.set('StkQty', mrp_obj.Balance_Qty)
                                            if (!obj[resourceId]) {
                                                obj[resourceId] = 0
                                            }
                                            ReqProcessed = parseFloat(mrp_obj.Shortage_Qty) - parseFloat(JSON.stringify(obj[resourceId]).replace(/\"/g, ""))
                                            ProcessingTime = Math.ceil(ReqProcessed / DailyEnergy);
                                            let maxCn = ProcessingTime * DailyEnergy;
                                            let FlQty = 0;//放量

                                            if (maxCn - ReqProcessed >= 0) {
                                                obj[resourceId] = maxCn - ReqProcessed
                                            } else {
                                                obj[resourceId] = obj[resourceId] - parseFloat(mrp_obj.Shortage_Qty)
                                            }
                                            record.set('Shortage_Qty', parseFloat(mrp_obj.Shortage_Qty))
                                            record.set('ReqProcessed', ReqProcessed > 0 ? ReqProcessed : 0)
                                            record.set('ProcessingTime', ProcessingTime)
                                            record.set('DeskQty', obj[resourceId])
                                        }
                                    }
                                })
                                store.resumeEvents();
                                grid.getView().refresh();
                                Alert('提示：', '计算完成！')
                            }, async: function () {

                            }
                        });
                    }, 500);

                }
            },
            {
                text: '预排',
                glyph: 0xf25b,
                handler: function () {
                    autoSort()
                }
            }, {
                text: '汇总输出',
                glyph: 0xf2ed,
                handler: function () {
                    let InvSumDataAry = [], SaOrderSumDataAry = [], ResourceSumDataAry = [];
                    store.sort('SaOrder', 'ASC');
                    store.each(function (record) {
                        if (record.get('Resource_ID') && record.get('Resource_ID') != "未配置") {
                            let item = InvSumDataAry.findIndex(x => x.InventoryID == record.get('InventoryID'))
                            if (item > -1) {
                                InvSumDataAry[item].Shortage_Qty += parseFloat(record.get('Shortage_Qty'));
                                InvSumDataAry[item].ReqQty += parseFloat(record.get('ReqQty'));
                                InvSumDataAry[item].ReqProcessed += parseFloat(record.get('ReqProcessed'));
                                InvSumDataAry[item].ProcessingTime += parseFloat(record.get('ProcessingTime'));
                                InvSumDataAry[item].DeskQty += parseFloat(record.get('DeskQty'));
                            } else {
                                InvSumDataAry.push({
                                    InventoryID: record.get('InventoryID'),
                                    Shortage_Qty: parseFloat(record.get('Shortage_Qty')),
                                    ReqQty: parseFloat(record.get('ReqQty')),
                                    ReqProcessed: parseFloat(record.get('ReqProcessed')),
                                    ProcessingTime: parseFloat(record.get('ProcessingTime')),
                                    DailyEnergy: parseFloat(record.get('DailyEnergy')),
                                    DeskQty: parseFloat(record.get('DeskQty')),
                                    ScheduleStartDate: record.get('SaDate')
                                })
                            }
                            let saOrderIndex = SaOrderSumDataAry.findIndex(x => x.OrderID == record.get('SaOrder'))
                            if (saOrderIndex > -1) {
                                SaOrderSumDataAry[saOrderIndex].Shortage_Qty += parseFloat(record.get('Shortage_Qty'));
                                SaOrderSumDataAry[saOrderIndex].ReqQty += parseFloat(record.get('ReqQty'));
                                SaOrderSumDataAry[saOrderIndex].ReqProcessed += parseFloat(record.get('ReqProcessed'));
                                SaOrderSumDataAry[saOrderIndex].ProcessingTime += parseFloat(record.get('ProcessingTime'));
                                SaOrderSumDataAry[saOrderIndex].DeskQty += parseFloat(record.get('DeskQty'));
                            } else {
                                SaOrderSumDataAry.push({
                                    OrderID: record.get('SaOrder'),
                                    Shortage_Qty: parseFloat(record.get('Shortage_Qty')),
                                    ReqQty: parseFloat(record.get('ReqQty')),
                                    ReqProcessed: parseFloat(record.get('ReqProcessed')),
                                    ProcessingTime: parseFloat(record.get('ProcessingTime')),
                                    DailyEnergy: parseFloat(record.get('DailyEnergy')),
                                    DeskQty: parseFloat(record.get('DeskQty')),
                                    ScheduleStartDate: record.get('SaDate'),
                                    ShipDate: record.get('ShipDate')
                                })
                            }
                            let resourceIndex = ResourceSumDataAry.findIndex(x => x.Resource_ID == record.get('Resource_ID'))
                            if (resourceIndex > -1) {
                                ResourceSumDataAry[resourceIndex].Shortage_Qty += parseFloat(record.get('Shortage_Qty'));
                                ResourceSumDataAry[resourceIndex].ReqQty += parseFloat(record.get('ReqQty'));
                                ResourceSumDataAry[resourceIndex].ReqProcessed += parseFloat(record.get('ReqProcessed'));
                                ResourceSumDataAry[resourceIndex].ProcessingTime += parseFloat(record.get('ProcessingTime'));
                                ResourceSumDataAry[resourceIndex].DeskQty += parseFloat(record.get('DeskQty'));
                            } else {
                                ResourceSumDataAry.push({
                                    Resource_ID: record.get('Resource_ID'),
                                    Shortage_Qty: parseFloat(record.get('Shortage_Qty')),
                                    ReqQty: parseFloat(record.get('ReqQty')),
                                    ReqProcessed: parseFloat(record.get('ReqProcessed')),
                                    ProcessingTime: parseFloat(record.get('ProcessingTime')),
                                    DailyEnergy: parseFloat(record.get('DailyEnergy')),
                                    DeskQty: parseFloat(record.get('DeskQty')),
                                    ScheduleStartDate: record.get('SaDate')
                                })
                            }
                        }
                    })
                    store.sort('InventoryID', 'ASC');
                    InvSumDataAry.forEach(element => {
                        element.ScheduleStartDate = AddDate(element.ScheduleStartDate, 1);
                        element['ScheduleEndDate'] = AddDate(element.ScheduleStartDate, element.ProcessingTime - 1);
                    });
                    SaOrderSumDataAry.forEach(element => {
                        element.ScheduleStartDate = AddDate(element.ScheduleStartDate, 1);
                        element['ScheduleEndDate'] = AddDate(element.ScheduleStartDate, element.ProcessingTime - 1);
                    });
                    ResourceSumDataAry.forEach(element => {
                        element.ScheduleStartDate = AddDate(element.ScheduleStartDate, 1);
                        element['ScheduleEndDate'] = AddDate(element.ScheduleStartDate, element.ProcessingTime - 1);
                    });
                    diyTabAry.forEach(x => {
                        manTabPanel.remove(x)
                    })
                    yPaiAddTab('成品汇总', 'InvSummData_storeId', [
                        {
                            text: '产品编码', dataIndex: 'InventoryID', flex: 1, renderer: function (value) {
                                let { Description } = InvAry.find(x => x.InventoryID == value)
                                return Description ? Description : value;
                            }
                        },
                        { text: '短缺量', dataIndex: 'Shortage_Qty' },
                        { text: '需求量', dataIndex: 'ReqQty' },
                        { text: '需加工', dataIndex: 'ReqProcessed' },
                        { text: '加工时长', dataIndex: 'ProcessingTime' },
                        { text: '产能', dataIndex: 'DailyEnergy' },
                        { text: '放量', dataIndex: 'DeskQty' },
                        { text: '预排开', dataIndex: 'ScheduleStartDate', xtype: 'datecolumn', format: 'Y-m-d' },
                        { text: '预排完', dataIndex: 'ScheduleEndDate', xtype: 'datecolumn', format: 'Y-m-d' },
                    ], InvSumDataAry);
                    yPaiAddTab('订单汇总', 'SaOrderSummData_storeId', [
                        {
                            text: '销售订单', dataIndex: 'OrderID', flex: 1,
                        },
                        { text: '短缺量', dataIndex: 'Shortage_Qty' },
                        { text: '需求量', dataIndex: 'ReqQty' },
                        { text: '需加工', dataIndex: 'ReqProcessed' },
                        { text: '加工时长', dataIndex: 'ProcessingTime' },
                        { text: '产能', dataIndex: 'DailyEnergy' },
                        { text: '放量', dataIndex: 'DeskQty' },
                        { text: '预排开', dataIndex: 'ScheduleStartDate', xtype: 'datecolumn', format: 'Y-m-d' },
                        { text: '预排完', dataIndex: 'ScheduleEndDate', xtype: 'datecolumn', format: 'Y-m-d' },
                        { text: '交货日期', dataIndex: 'ShipDate', xtype: 'datecolumn', format: 'Y-m-d' },
                    ], SaOrderSumDataAry);
                    yPaiAddTab('车间汇总', 'WorkShopSummData_storeId', [
                        {
                            text: '车间', dataIndex: 'Resource_ID', renderer: function (value) {
                                let valObj = WorkShopLineList.find(x => x.Code_ID == value)
                                return valObj ? valObj.Description : value;
                            }
                        },
                        { text: '短缺量', dataIndex: 'Shortage_Qty', xtype: 'numbercolumn', format: '0.00' },
                        { text: '需求量', dataIndex: 'ReqQty', xtype: 'numbercolumn', format: '0.00' },
                        { text: '需加工', dataIndex: 'ReqProcessed', xtype: 'numbercolumn', format: '0.00' },
                        { text: '加工时长', dataIndex: 'ProcessingTime', xtype: 'numbercolumn', format: '0.00' },
                        { text: '产能', dataIndex: 'DailyEnergy', xtype: 'numbercolumn', format: '0.00' },
                        { text: '放量', dataIndex: 'DeskQty', xtype: 'numbercolumn', format: '0.00' },
                        { text: '预排开', dataIndex: 'ScheduleStartDate', xtype: 'datecolumn', format: 'Y-m-d' },
                        { text: '预排完', dataIndex: 'ScheduleEndDate', xtype: 'datecolumn', format: 'Y-m-d' },
                    ], ResourceSumDataAry);
                    Alert('提示：', '汇总输出完成！')
                }
            }, {
                text: '删除',
                glyph: 0xf2ed,
                handler: function () {
                    let records = grid.getSelection();
                    if (records.length > 0) {
                        Confirm('提示：', "确定删除？", function () {
                            grid.getStore().remove(records[0])
                        }, null, null)
                    }
                }
            }, '->',
            {
                text: '导出Excel',
                glyph: 0xf1c3,
                handler: function () {
                    grid2Excel(grid, "分单预排清单");
                }
            }
        ]

    });
    var grid = getTopWindow().Ext.create('Ext.grid.Panel', {
        store: store,
        stripeRows: true,
        title: '分单',
        height: 200,
        enableDragDrop: true,
        viewConfig: {
            plugins: {
                ptype: 'gridviewdragdrop',
                //dragGroup :'DragDropGroup',
                enableDrag: true,
                enableDrop: true
            },
            listeners: {
                drop: function (node, data, overModel, dropPosition, eOpts) {
                    autoSort();
                }
            },
            forceFit: true,
        },
        // features: [
        //     {
        //         groupHeaderTpl: [
        //             '订单: {name:this.formatName}',
        //             {
        //                 formatName: function (name, opt) {
        //                     return name;
        //                 }
        //             }
        //         ],
        //         ftype: 'groupingsummary'
        //     }
        // ],
        plugins: {
            ptype: 'cellediting',
            clicksToEdit: 1,
            gridfilters: true,
        },
        columns: [
            { header: '', xtype: 'rownumberer', width: 45, align: 'center', sortable: false, menuDisabled: true },
            { header: '销售订单', dataIndex: 'SaOrder', width: 135, hidden: false, locked: true, align: 'center', sortable: false, menuDisabled: true },
            { header: '下单日期', dataIndex: 'SaDate', xtype: 'datecolumn', locked: true, format: 'Y-m-d', width: 90, align: 'center', sortable: false, menuDisabled: true },
            {
                header: '产品编码', dataIndex: 'InventoryID', width: 200, locked: true, align: 'center', sortable: false, menuDisabled: true, renderer: function (value) {
                    let { Description } = InvAry.find(x => x.InventoryID == value)
                    return Description ? Description : value;
                }
            },
            { header: '产品名称', dataIndex: 'Description', width: 200, locked: false, hidden: true, align: 'center', sortable: false, menuDisabled: true },
            { header: '净重', dataIndex: 'Unit_Weight', width: 50, align: 'center', sortable: false, menuDisabled: true },
            {
                header: '罐型', dataIndex: 'JarmodelID', width: 120, align: 'center', sortable: false, menuDisabled: true, renderer: function (value) {
                    let valObj = JarmodelAry.find(x => x.Inventory_ID == value)
                    return valObj ? valObj.Description : value;
                }
            },
            {
                header: '箱型', dataIndex: 'BoxCode', width: 100, align: 'center', sortable: false, menuDisabled: true, renderer: function (value) {
                    let valObj = BoxAry.find(x => x.Inventory_ID == value)
                    return valObj ? valObj.Description : value;
                }
            },
            { header: '件规格', dataIndex: 'Nbox', width: 75, align: 'center', sortable: false, menuDisabled: true },
            {
                header: '车间', dataIndex: 'Resource_ID', width: 110, align: 'center', hidden: false, sortable: false, menuDisabled: true, renderer: function (value) {
                    let valObj = WorkShopLineList.find(x => x.Code_ID == value)
                    return valObj ? valObj.Description : value;
                }
            },
            { header: '库存', dataIndex: 'StkQty', width: 50, summaryType: 'sum', align: 'center', sortable: false, menuDisabled: true },
            { header: '预排开', dataIndex: 'ScheduleStartDate', width: 90, align: 'center', sortable: false, menuDisabled: true },
            { header: '预排完', dataIndex: 'ScheduleEndDate', width: 90, align: 'center', sortable: false, menuDisabled: true },
            { header: '车间+放量', dataIndex: 'DeskQty', width: 90, summaryType: 'sum', align: 'center', sortable: false, menuDisabled: true },
            { header: '短缺数', dataIndex: 'Shortage_Qty', width: 90, align: 'center', sortable: false, menuDisabled: true },
            { header: 'Q未下', dataIndex: 'QtyNotOrder', xtype: 'numbercolumn', format: '0.00' },
            { header: 'Q未完', dataIndex: 'QtyNotFinish', xtype: 'numbercolumn', format: '0.00' },
            { header: '需求量', dataIndex: 'ReqQty', width: 90, align: 'center', sortable: false, menuDisabled: true },
            { header: '需加工', dataIndex: 'ReqProcessed', width: 90, align: 'center', sortable: false, menuDisabled: true },
            { header: '日产能', dataIndex: 'DailyEnergy', width: 90, align: 'center', sortable: false, menuDisabled: true },
            { header: '加工时长', dataIndex: 'ProcessingTime', width: 90, align: 'center', sortable: false, menuDisabled: true },
            { header: '交货日期', dataIndex: 'ShipDate', xtype: 'datecolumn', locked: true, format: 'Y-m-d', width: 90, align: 'center', sortable: false, menuDisabled: true },
            { header: '销售订单行号', dataIndex: 'NOID', width: 110, hidden: true, align: 'center', sortable: false, menuDisabled: true },
            { header: '加工分类', dataIndex: 'MfgCatID', width: 90, hidden: true, align: 'center', sortable: false, menuDisabled: true }
        ],
        listeners: {
            "afterrender": function (that) {
                TblMfgCatIdInvAry = getListWithMultParams("TblMfgCatIdInv", { Type: '2' });
                WorkShopLineList = getListWithMultParams("WorkShopLine", {});
                JarmodelAry = getListWithMultParams("Inventory", { Type: '4' });
                BoxAry = getListWithMultParams("Inventory", { Type: '5' });
                ResourceAry = getListWithMultParams("Resource", {});
            },
            edit: function (editor, context, eOpts) {
                //autoWeightKey(context.record);
            }
        }
    });
    manTabPanel = Ext.create('Ext.tab.Panel', {
        dockedItems: [toolTbar],
        items: [grid]
    });
    return manTabPanel;
}
